package com.yanfan.ccapi.controller;

import com.yanfan.ccapi.service.ICcapiUserAuthorizeService;
import com.yanfan.ccapicode.dao.entity.UserAuthorizeDO;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 云云对接用户授权Controller
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@RestController
@RequestMapping("/ccapi/userAuthorize")
@Api(tags = "云云对接用户授权")
public class CcapiUserAuthorizeController extends BaseController {
    @Autowired
    private ICcapiUserAuthorizeService ccapiUserAuthorizeService;

    /**
     * 查询云云对接用户授权列表
     */
//@PreAuthorize("@ss.hasPermi('ccapi:userAuthorize:list')")
    @GetMapping("/list")
    @ApiOperation("查询云云对接用户授权列表")
    public TableDataInfo list(UserAuthorizeDO ccapiUserAuthorize) {
        startPage();
        List<UserAuthorizeDO> list = ccapiUserAuthorizeService.selectCcapiUserAuthorizeList(ccapiUserAuthorize);
        return getDataTable(list);
    }

    /**
     * 导出云云对接用户授权列表
     */
    @ApiOperation("导出云云对接用户授权列表")
    //@PreAuthorize("@ss.hasPermi('ccapi:userAuthorize:export')")
    @Log(title = "云云对接用户授权", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAuthorizeDO ccapiUserAuthorize) {
        List<UserAuthorizeDO> list = ccapiUserAuthorizeService.selectCcapiUserAuthorizeList(ccapiUserAuthorize);
        ExcelUtil<UserAuthorizeDO> util = new ExcelUtil<UserAuthorizeDO>(UserAuthorizeDO.class);
        util.exportExcel(response, list, "云云对接用户授权数据");
    }

    /**
     * 获取云云对接用户授权详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:userAuthorize:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取云云对接用户授权详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ccapiUserAuthorizeService.selectCcapiUserAuthorizeById(id));
    }

    /**
     * 新增云云对接用户授权
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:userAuthorize:add')")
    @Log(title = "云云对接用户授权", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增云云对接用户授权")
    public AjaxResult add(@RequestBody UserAuthorizeDO ccapiUserAuthorize) {
        return toAjax(ccapiUserAuthorizeService.insertCcapiUserAuthorize(ccapiUserAuthorize));
    }

    /**
     * 修改云云对接用户授权
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:userAuthorize:edit')")
    @Log(title = "云云对接用户授权", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改云云对接用户授权")
    public AjaxResult edit(@RequestBody UserAuthorizeDO ccapiUserAuthorize) {
        return toAjax(ccapiUserAuthorizeService.updateCcapiUserAuthorize(ccapiUserAuthorize));
    }

    /**
     * 删除云云对接用户授权
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:userAuthorize:remove')")
    @Log(title = "云云对接用户授权", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除云云对接用户授权")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ccapiUserAuthorizeService.deleteCcapiUserAuthorizeByIds(ids));
    }
}
